package bCommon
{
	import bComponent.Waiting;
	
	import com.adobe.ac.mxeffects.CubeRotate;
	import com.adobe.ac.mxeffects.DistortionConstants;
	
	import fl.core.UIComponent;
	
	import flash.display.DisplayObject;
	import flash.external.ExternalInterface;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.formatters.DateFormatter;
	import mx.utils.ObjectUtil;
	
	import spark.components.ComboBox;
	import spark.components.supportClasses.DropDownListBase;
	
	
	public class Util
	{
		import flash.utils.ByteArray;
		
		public function Util()
		{
		}

		public static function cloneObj(_source:Object):*
		{
			return ObjectUtil.copy(_source);
		}
		
		public static function selectedCombox(combox:DropDownListBase,data:Object,name:String="data"):void
		{
			var j:ArrayCollection=ArrayCollection(combox.dataProvider);
			for(var i:int=0;i<j.length;i++)
			{
				if(j.getItemAt(i)[name]==data)
				{
					combox.selectedIndex=i;
					break;
				}	
			}
		}
		
		public static function GetObjectInfo(_favStuff:Object):String
		{
			var obj:Object = ObjectUtil.getClassInfo( _favStuff );
			var buf:String="";			
			var len:int = obj.properties.length;
			for( var i:int = 0; i < len; i++ ) { 
				buf += obj.properties[i].localName + "=";
				buf += _favStuff[ obj.properties[i] ] + " ";
			}
			return buf;
		}
		
		public static function AddDay(date:Date,days:int):Date 
		{
			var n:Number = 1000*60*60*24*days; 
			return new Date(date.time+n);
		}
		
		/** 返回两个日期相差的天数**/
		public static function GetDays(date1:Date,date2:Date):Number 
		{
			return (date2.time-date1.time)/(1000*60*60*24);
		}
		
		/** 返回两个日期相差的秒数 **/
		public static function GetSeconds(min:Date,max:Date):Number 
		{
			return (max.time-min.time)/(1000);
		}
		
		public static function GetDayString(date:Date):String 
		{
			var df:DateFormatter = new DateFormatter(); 
			df.formatString = 'YYYY-MM-DD HH:NN:SS'; 
			return df.format(date); 
		}	
		
		public static function GetShortDayString(date:Date):String 
		{
			var df:DateFormatter = new DateFormatter(); 
			df.formatString = 'YYYY-MM-DD'; 
			return df.format(date); 
		}
		
		public static function CheckIPString(ipStr:String):Boolean 
		{
			if(!ipStr||ipStr=="") return false;
			var ip2:RegExp =/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
			return ip2.test(ipStr);  
		}
		
		public static function alert(msg:Object):Alert{
			return Alert.show("\n"+msg+"\n","提示");
		}
		
		public static function alert4ie(msg:Object):void{
			ExternalInterface.call("top.alert",msg);
		}
		
		public static function effectRollBottom2Top(object:Object,duration:int){
			var pop:CubeRotate = new CubeRotate(object);
			pop.siblings = [object];
			pop.direction = DistortionConstants.TOP;
			pop.duration = duration;
			//pop.addEventListener(EffectEvent.EFFECT_END,onEndBlueToYellowEffect);
			pop.play();
		}
		
		public static function getRealZoom(zoom:int):int{
			return 17-zoom;
		}
		
		public static function openWaiting():void{
			Waiting.waiting.open();
		}
		
		public static function closeWaiting():void{
			Waiting.waiting.close();
		}
		
		public static function setStatus(msg:Object):void{
			CommonData.baseEventDispatcher.sendEvent({type:BaseEvent.APPLICATION_UPDATE_STATUS,parameter:msg+""});
		}
		
		public static function appendStatus(msg:Object):void{
			CommonData.baseEventDispatcher.sendEvent({type:BaseEvent.APPLICATION_APPEND_STATUS,parameter:msg+""});
		}
	}
}






















